﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;


namespace TM_Server
{
    class Request2Number
    {

        #region 全局变量部分

        SqlDataReader dr;
        SqlConnection Connection = new SqlConnection("Data Source=(local);Initial Catalog=TM_Numbers_Infomations;Persist Security Info=True;User ID=sa;Password=songna0917");

        #endregion

        #region 获取数据库未被注册的QQ号码

        /*
         * 此方法用来获取数据库未被注册的QQ号码
         * 并且传回
         */
        public String GetNumber()
        {
           try
           {
               Connection.Open();  //打开数据库
               String Order = "SELECT TOP 1 * FROM TM_Num WHERE TM_IsSign = 0";
               SqlCommand Command = new SqlCommand(Order,Connection);
               //返回Reader对象
               SqlDataReader dr = Command.ExecuteReader();
               while(dr.Read())
               {
                   //读取QQ号码
                   String QQ_Now = dr[0].ToString();
                   dr.Close();
                   return QQ_Now;
               }
               return "NO";
           }
           catch (Exception ex)
           {
               return "NO";
               MessageBox.Show("连接数据库失败：" + ex.Message);
           }
       }

        #endregion

        #region 此方法为设置QQ已被注册

        /*
         * 此方法为设置QQ已被注册
         */
        public int Set_Signd(String QQ)
        {
            try
            {
                String Order = "Update TM_Num Set TM_IsSign = 1 Where TM_Numbers = " + QQ;
                SqlCommand Command = new SqlCommand(Order, Connection);
                Command.ExecuteNonQuery();
                return 0;
            }
            catch(Exception ex)
            {
                MessageBox.Show("标识未成功：" + ex.Message);
                return 1;
            }
        }

       #endregion

    }
}
